﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Timers;

namespace MyService
{
    public partial class MyService : ServiceBase
    {
        public MyService()
        {
            InitializeComponent();
            timer = new Timer(1000);
            timer.Elapsed += timer_Elapsed;
        }

        void timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            Log.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
        }

        private Timer timer = null;
        WebAPIHelper api = new WebAPIHelper("9875");
        protected override void OnStart(string[] args)
        {
            Log.WriteLog("执行OnStart方法");
            if (null != timer)
                timer.Start();
            Log.WriteLog("WebAPI Start...");
           
            api.Open();
            Log.WriteLog("WebAPI Open OK .... ");

        }

        protected override void OnStop()
        {
            Log.WriteLog("执行OnStop方法");
            timer.Stop();
            timer.Dispose();

            Log.WriteLog("WebAPI Close...");
            api.Close();
            Log.WriteLog("WebAPI Close OK...");

        }
    }
}
